package com.yc;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @program: concurrent
 * @description: socket
 * @author: zy
 * @create: 2022-01-13 10:59
 */
public class Test2_client {
    //编写第一个客户端
    public static void main(String[] args) throws IOException {
        InetAddress[] ia2= InetAddress.getAllByName("www.baidu.com");
        if( ia2!=null){
            // baidu服务器的ip有多个,
            for(  InetAddress ia: ia2){
               // System.out.println(   ia );
                Socket client=new Socket(ia,80);
                System.out.println("联接成功,"+ client);   //Socket[addr=www.baidu.com/183.2.172.42,port=80,localport=50948]
                                                         //基于TCP的客户端套接字对象             本机的发送端口
                //本地端口  localport是随机选的
                break;
            }
        }

        Socket client2=new Socket("www.baidu.com",80);
        System.out.println(  "联接成功2"+ client2 );


        Socket client3=new Socket("45.113.192.102",80);
        System.out.println(  "联接成功3"+ client3 );
    }
}
